package org.infodavid.common.model;

import java.util.ArrayList;
import java.util.List;

import org.infodavid.common.IBuilder;
import org.infodavid.common.dto.IUserGroupListItem.EUserRole;
import org.infodavid.common.ejb.UserGroupBean;

/**
 * The Class GroupTest.
 */
public class GroupTest extends AbstractBeanTest<IUserGroup> {
	private static final EUserRole[] ROLES;

	static {
		// not system
		ROLES = new EUserRole[EUserRole.values().length - 1];
		int i = 0;

		for (EUserRole item : EUserRole.values()) {
			if (item != EUserRole.SYSTEM) {
				ROLES[i++] = item;
			}
		}
	}

	/**
	 * Instantiates a new group test.
	 * @param mainTest the main test
	 */
	public GroupTest(final AbstractPersistenceTest mainTest) {
		super(mainTest);
	}

	/**
	 * Instantiates a new group test.
	 */
	public GroupTest() {
		super();
	}

	/**
	 * Populate.
	 * @param count the count
	 * @return the collection< test data>
	 * @throws Exception the exception
	 */
	@Override
	protected List<IUserGroup> doCreate(final int count) throws Exception {
		final IBuilder<IUserGroup> builder = ModelFactory.getInstance().getBuilder(IUserGroup.class);
		final List<IUserGroup> items = new ArrayList<IUserGroup>(count);
		IUserGroup item;
		long key;

		for (int i = 0; i < count; i++) {
			item = builder.create();
			key = System.nanoTime();

			item.setArchived(false);
			item.setName("item-" + key);
			item.setComment("comment-" + key);
			item.setGuest(RAND.nextBoolean());
			item.setRole(ROLES[RAND.nextInt(ROLES.length)]);
			item.getProperties().addData("key1", "value1");
			item.getProperties().addData("key2", "value2");

			items.add(item);
		}

		return items;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityClass()
	 */
	@Override
	public Class<UserGroupBean> getEntityClass() {
		return UserGroupBean.class;
	}

	/**
	 * See super class or interface. (non-Javadoc)
	 * @see org.infodavid.common.model.AbstractBeanTest#getEntityName()
	 */
	@Override
	public String getEntityName() {
		return IUserGroup.class.getSimpleName();
	}
}
